home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_53898.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  24 lines

  1. -- card: 53898 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. solution is to define an improved version of this macro:
  11.  
  12.     # define        SQUARE(x)       ((x) * (x))
  13.  
  14. In conclusion, it is generally wise to enclose each occurence of the parameter in the replacement text with parentheses, and enclose the entire replacement text with parentheses.
  15.  
  16. Macros with parameters may be more efficient than genuine functions which perform the same task, by eliminating the need for argument passing, variable allocation, etc.  On the other hand, the argument "passed" to a macro must be evaluated once for each occurence of the parameter in the replacement text.  If the argument is an expression which is difficult to evaluate, the macro may be LESS efficient than an equivalent function.  For example, consider the "call":
  17.  
  18.         result = SQUARE(  sqrt(SQUARE(sin(x))+SQUARE(cos(x)))+1.  );
  19.  
  20. The expression "passed" is evaluated twice after expansion of the macro.
  21.  
  22. -- part contents for background part 7
  23. ----- text -----
  24. 173